package top.malaoshi.controller;

import org.springframework.web.bind.annotation.*;
import top.malaoshi.entity.Notice;
import top.malaoshi.model.JsonResult;
import top.malaoshi.service.NoticeServiceImpl;

import javax.annotation.Resource;
import java.util.Date;

@RestController
public class NoticeCtrl {
    @Resource
    private NoticeServiceImpl noticeService;

    @GetMapping(value="/getNoticeById/{id}")
    public JsonResult<Notice> getNoticeById(@PathVariable("id") String id){
        System.out.println("=====id:"+id+"--"+new Date());

        Notice notice=noticeService.getNoticeById(id);
        JsonResult res=new JsonResult(200,"成功！");
        res.setData(notice);
        return res;
    }
    //url后面没有/，client发请求时有没有/都可以。如果这里有/，那么client发请求时必须带上/
    @PostMapping(value="/sendNotice")
    public JsonResult sendNotice(@RequestBody Notice notice){
        noticeService.sendNotice(notice);
        return new JsonResult(200,"成功！");
    }
}
